/*
 * Queue Sample
 */
public class Queue<T> {
   private Node<T> nodeHead = null;
   private Node<T> nodeEnd = null;
   private long size = 0L;
 
   public void enqueue(T x) {
      Node<T> newNode = new Node<T>(x, null);
      if (nodeHead == null) {
         nodeHead = newNode;
      } else {
         nodeEnd.next = newNode;
      }
      nodeEnd = newNode;
      size++;
   }
 
   public T dequeue() throws IllegalArgumentException {
      if (nodeHead == null) {
         throw new IllegalArgumentException();
      }
      T head = nodeHead.element;
      nodeHead = nodeHead.next;
      size--;
 
      return head;
   }
 
   public long size() {
      return size;
   }
 
   private class Node<T> {
      Node<T> next;
      T element;
 
      public Node(T element, Node<T> next) {
         this.element = element;
         this.next = next;
      }
   }
}